using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using OgilvyOne.Model;
using OgilvyOne.BLL;
using System.Web;

namespace OgilvyOne.ProcessFlow
{
    public class FuncRoleController
    {
        // Fields
        private string bgColor = "#EEEEEE";
        private const string URL_DEFAULT = "/systemmanage/role/role_list.aspx";
       // private const string URL_ITEMCREATE = "sysmenu_add.aspx";
       // private const string URL_ITEMUPDATE = "sysmenu_modify.aspx";

        // Methods
        public bool CreateFuncRole(string[] func_uid, int iRole_uid)
        {
            try
            {
                FuncRole role = new FuncRole();
                role.DeleteByRoleID(iRole_uid);
                if (func_uid != null)
                {
                    for (int i = 0; i < func_uid.Length; i++)
                    {
                        FuncRoleInfo func = new FuncRoleInfo(int.Parse(func_uid[i]), iRole_uid);
                        role.Insert(func);
                    }
                }
                HttpContext.Current.Response.Redirect(URL_DEFAULT, true);
            }
            catch
            {
                return false;
            }
            return true;
        }

        public string getFuncRoleList(int role_uid)
        {
            string str = "";
            try
            {
                IList list = new Func().getFuncList();
                string str2 = "";
                IList list2 = new FuncRole().getFuncListByRoleID(role_uid);
                for (int i = 0; i < list.Count; i++)
                {
                    FuncInfo info2 = (FuncInfo)list[i];
                    str = str + "<tr>";
                    str = str + "<td width=\"586\" bgcolor=\"" + this.bgColor + "\">" + info2.Function_Name + "</td>";
                    str2 = "";
                    for (int j = 0; j < list2.Count; j++)
                    {
                        FuncRoleInfo info = (FuncRoleInfo)list2[j];
                        if (info.Function_UID == info2.Function_UID)
                        {
                            str2 = " checked";
                        }
                    }
                    str = string.Concat(new object[] { str, "<td width=\"105\" bgcolor=\"", this.bgColor, "\"><input type=checkbox name=chk value=", info2.Function_UID, str2, "></td>" });
                    str = str + "</tr>";
                }
            }
            catch
            {
                return str;
            }
            return str;
        }

    }
}
